package com.proposition.exam.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.proposition.commons.exam.result.Result;
import com.proposition.commons.exam.result.ResultUtil;
import com.proposition.commons.exam.util.ExamAddUtil;
import com.proposition.commons.exam.util.ExamFieldVolidateUtil;
import com.proposition.commons.exam.util.ExamUtil;
import com.proposition.commons.model.ExamAcupoint;
import com.proposition.commons.model.ExamAcupointOriginal;
import com.proposition.exam.mapper.ExamAcupointMapper;
import com.proposition.exam.service.ExamAcupointService;
import com.proposition.support.security.CurrentUser;
import com.proposition.support.utils.UUIDUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 14:19 2017/11/2
 * @description:问答题-腧穴试题服务类接口实现类
 */
@Service
public class ExamAcupointServiceImpl extends ServiceImpl<ExamAcupointMapper, ExamAcupoint> implements ExamAcupointService {
    @Transactional
    @Override
    public Result add(String[] answerWD, Float[] answerWDScore, String[] answerWD1, Float[] answerWDScore1, ExamAcupoint exam, ExamAcupointOriginal examOriginal) {
        String stem = ExamFieldVolidateUtil.getIllegalStem(exam.getStem());
        exam.setStem(stem);
        ExamAddUtil.volidateUniqueStem(exam);
        //验证大纲代码
        ExamUtil.volidateOutlineCode(exam.getOutlineCode());
        String id = UUIDUtil.getExamUUIDByCategory("01");
        String userIdImport = CurrentUser.INSTANCE.getUserId();
        exam.setId(id);//设置id
        exam.setUserIdImport(userIdImport);//设置当前导入用户id
        //设置定位
        for (int i = 0; i < answerWD.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setLocation1(answerWD[i]);
                    examOriginal.setLocation1(answerWD[i]);
                    break;
                case 2:
                    exam.setLocation2(answerWD[i]);
                    examOriginal.setLocation2(answerWD[i]);
                    break;
                case 3:
                    exam.setLocation3(answerWD[i]);
                    examOriginal.setLocation3(answerWD[i]);
                    break;
                default:
                    break;
            }
        }
        for (int i = 0; i < answerWDScore.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setLocation1Score(answerWDScore[i]);
                    examOriginal.setLocation1Score(answerWDScore[i]);
                    break;
                case 2:
                    exam.setLocation2Score(answerWDScore[i]);
                    examOriginal.setLocation2Score(answerWDScore[i]);
                    break;
                case 3:
                    exam.setLocation3Score(answerWDScore[i]);
                    examOriginal.setLocation3Score(answerWDScore[i]);
                    break;

                default:
                    break;
            }
        }

        //设置主治
        for (int i = 0; i < answerWD1.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setMayorCure1(answerWD1[i]);
                    examOriginal.setMayorCure1(answerWD1[i]);
                    break;
                case 2:
                    exam.setMayorCure2(answerWD1[i]);
                    examOriginal.setMayorCure2(answerWD1[i]);
                    break;
                case 3:
                    exam.setMayorCure3(answerWD1[i]);
                    examOriginal.setMayorCure3(answerWD1[i]);
                    break;
                case 4:
                    exam.setMayorCure4(answerWD1[i]);
                    examOriginal.setMayorCure4(answerWD1[i]);
                    break;
                case 5:
                    exam.setMayorCure5(answerWD1[i]);
                    examOriginal.setMayorCure5(answerWD1[i]);
                    break;
                case 6:
                    exam.setMayorCure6(answerWD1[i]);
                    examOriginal.setMayorCure6(answerWD1[i]);
                    break;
                case 7:
                    exam.setMayorCure7(answerWD1[i]);
                    examOriginal.setMayorCure7(answerWD1[i]);
                    break;
                case 8:
                    exam.setMayorCure8(answerWD1[i]);
                    examOriginal.setMayorCure8(answerWD1[i]);
                    break;
                default:
                    break;
            }
        }
        for (int i = 0; i < answerWDScore1.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setMayorCure1Score(answerWDScore1[i]);
                    examOriginal.setMayorCure1Score(answerWDScore1[i]);
                    break;
                case 2:
                    exam.setMayorCure2Score(answerWDScore1[i]);
                    examOriginal.setMayorCure2Score(answerWDScore1[i]);
                    break;
                case 3:
                    exam.setMayorCure3Score(answerWDScore1[i]);
                    examOriginal.setMayorCure3Score(answerWDScore1[i]);
                    break;
                case 4:
                    exam.setMayorCure4Score(answerWDScore1[i]);
                    examOriginal.setMayorCure4Score(answerWDScore1[i]);
                    break;
                case 5:
                    exam.setMayorCure5Score(answerWDScore1[i]);
                    examOriginal.setMayorCure5Score(answerWDScore1[i]);
                    break;
                case 6:
                    exam.setMayorCure6Score(answerWDScore1[i]);
                    examOriginal.setMayorCure6Score(answerWDScore1[i]);
                    break;
                case 7:
                    exam.setMayorCure7Score(answerWDScore1[i]);
                    examOriginal.setMayorCure7Score(answerWDScore1[i]);
                    break;
                case 8:
                    exam.setMayorCure8Score(answerWDScore1[i]);
                    examOriginal.setMayorCure8Score(answerWDScore1[i]);
                    break;
                default:
                    break;
            }
        }
        exam.insert();

        examOriginal.setId(id);
        examOriginal.setUserIdImport(userIdImport);
        examOriginal.insert();
        return ResultUtil.sucess();
    }
}

